package com.hibernate.account ;
import org.hibernate.Session;
import org.hibernate.Transaction;

import com.hibernate.domain.Account;
import com.hibernate.utils.HibernateUtils;

public class AccountDao extends HibernateUtils{
	/**
	 * 在给定的账号(11)上减少100
	 * @param account
	 */
	public void removeMoney(Long account){
		Session session = sessionFactory.openSession();
		Transaction transaction = session.beginTransaction();
		Account account2 = (Account)session.createQuery("from Account where account="+account)
				.uniqueResult();
		account2.setMoney(account2.getMoney()-100);
		transaction.commit();
		session.close();
	}
	
	public void removeMoney_Super(Long account,Session session){
		
		Account account2 = (Account)session.createQuery("from Account where account="+account)
				.uniqueResult();
		account2.setMoney(account2.getMoney()-100);
		
	}
	
	/*
	 * 给定的账号(22)加100元
	 */
	public void addMoney(Long account){
		Session session = sessionFactory.openSession();
		Transaction transaction = session.beginTransaction();
		Account account2 = (Account)session.createQuery("from Account where account="+account)
				.uniqueResult();
		account2.setMoney(account2.getMoney()+100);
		transaction.commit();
		session.close();
	}
	
	public void addMoney_Super(Long account,Session session){
		Account account2 = (Account)session.createQuery("from Account where account="+account)
				.uniqueResult();
		int a = 1/0;
		account2.setMoney(account2.getMoney()+100);
	}
}
